home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / OS2LIB.ZIP / DEMO.C < prev    next >
Text File  |  1993-05-23  |  2KB  |  108 lines

  1. #define NUM 9
  2. #include <os2.h>
  3. #include "xlibos2.h"
  4.  
  5.  
  6. struct POS {
  7.    int x,y;
  8. };
  9.  
  10. struct MY_DEMO {
  11.    struct POS pos;
  12.    int spx,spy;
  13.    char xdir,ydir;
  14. };
  15.  
  16.  
  17. void iSprites(struct MY_DEMO *spr,char number)
  18. {
  19.     char i;
  20.  
  21.     for (i=0;i<number;i++) {
  22.        spr[i].pos.x=rand()%300;
  23.        spr[i].pos.y=rand()%200;
  24.        spr[i].spx=(rand()%6)+1;
  25.        spr[i].spy=(rand()%6)+1;
  26.        spr[i].xdir=1;
  27.        spr[i].ydir=1;
  28.     }
  29. }
  30.  
  31. void uSprite(struct MY_DEMO *spr)
  32. {
  33.     if (spr->xdir==1) {
  34.        spr->pos.x=spr->pos.x+spr->spx;
  35.     } else {
  36.        spr->pos.x=spr->pos.x-spr->spx;
  37.     }
  38.     if (spr->ydir==1) {
  39.        spr->pos.y=spr->pos.y+spr->spx;
  40.     } else {
  41.        spr->pos.y=spr->pos.y-spr->spx;
  42.     }
  43.  
  44.     if (spr->pos.x > 290)
  45.        spr->xdir=0;
  46.     if (spr->pos.x < 10)
  47.        spr->xdir=1;
  48.     if (spr->pos.y > 210)
  49.        spr->ydir=0;
  50.     if (spr->pos.y < 10)
  51.        spr->ydir=1;
  52. }
  53.  
  54. main(int argc, char *argv[], char *envp[])
  55. {
  56.    int i;
  57.    int x=0;
  58.    struct IMAGE_TABLE MySprite;
  59.    struct POS EraseQueue[NUM];
  60.    struct MY_DEMO sprite[NUM];
  61.    struct PAGE_TABLE pageTable;
  62.    CHAR Apage=1,Vpage=0;
  63.  
  64.  
  65.  
  66.    InitModeX(&pageTable);
  67.    iSprites(sprite,NUM);
  68.    XCLoadImage("demo.obv",&MySprite);
  69.    XCls(0);
  70.  
  71.    for (i=0;i<255;i++) {
  72.        XBoxAt(0,0,rand()%300,rand()%200,rand()%(i+1));
  73.        XWaitRetrace();
  74.    }
  75.    XLoadCel("grantp.cel",pageTable.p[0]);
  76.    XCopyFromPageToPage(0,0,0,320,340,1,0,0);
  77.    XCopyFromPageToPage(1,0,0,320,340,2,0,0);
  78.  
  79.    for (i=0;i<NUM;i++) 
  80.       XCBltImage(sprite[i].pos.x,sprite[i].pos.y,&MySprite);
  81.    for (i=0;i<NUM;i++) {
  82.       EraseQueue[i]=sprite[i].pos;
  83.    }
  84.  
  85.  
  86.    while (!_kbhit()) {
  87.        Apage++;
  88.        Vpage++;
  89.        XSetActivePage(Apage&0x01);
  90.        XSetVisualPage(Vpage&0x01);
  91.  
  92.        for (i=0;i<NUM;i++) {
  93.           XCopyFromPageToPage(2,EraseQueue[i].x,EraseQueue[i].y,20,16,Apage&0x01,EraseQueue[i].x,EraseQueue[i].y);
  94.        }
  95.        for (i=0;i<NUM;i++) {
  96.           EraseQueue[i]=sprite[i].pos;
  97.        } 
  98.        for (i=0;i<NUM;i++) {
  99.           uSprite(&sprite[i]);
  100.        }
  101.        for (i=0;i<NUM;i++) {
  102.           XCBltImage(sprite[i].pos.x,sprite[i].pos.y,&MySprite);
  103.        }
  104.    } 
  105.  
  106.    CloseModeX();
  107. }
  108.